define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'finance/money_logs/index' + location.search,
                    add_url: 'finance/money_logs/add',
                    // edit_url: 'finance/money_logs/edit',
                    // del_url: 'finance/money_logs/del',
                    multi_url: 'finance/money_logs/multi',
                    import_url: 'finance/money_logs/import',
                    table: 'shop',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search:false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'middleman.no', title: '经纪人id'},
                        {field: 'user.nickname', title: '用户昵称'},
                        {field: 'middleman.real_name', title: '真实姓名'},
                        {field: 'middleman.phone', title: '手机号'},
                        {field: 'memo', title: '变动类型', operate: false},
                        {field: 'money', title: '变动金额', operate: false},
                        {field: 'before_money', title: '变动前金额', operate: false},
                        {field: 'after_money', title: '变动后金额', operate: false},
                        {field: 'user.area', title: '区域', operate: false},
                        {field: 'operation_name', title: '操作管理员', operate: false},
                        {field: 'create_dt', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'update_dt', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        
                        // {
                        //     field: "operate",
                        //     title: __("Operate"),
                        //     table: table,
                        //     events: Table.api.events.operate,
                        //     buttons: [{
                        //         name: "agree",
                        //         title: "审核通过",
                        //         classname: "btn btn-xs btn-success btn-magic btn-ajax",
                        //         icon: "fa fa-check",
                        //         text: "同意",
                        //         confirm: "确认点击同意，通过审核？",
                        //         url: "finance/money_logs/agree",
                        //         visible: function(row){
                        //             if ("0" == row.log_status) return ! 0
                        //         }, 
                        //         refresh: true
                        //     },
                        //     {
                        //         name: "refuse",
                        //         title: __("审核不通过"),
                        //         classname: "btn btn-xs btn-danger btn-dialog",
                        //         icon: "fa fa-times",
                        //         text: "拒绝",
                        //         url: "finance/money_logs/refuse",
                        //         extend: 'data-area=["500px","270px"]',
                        //         visible: function(row){
                        //             if ("0" == row.log_status) return ! 0
                        //         }, 
                        //         refresh: true,
                        //     },
                        //     // {
                        //     //     name: "edit",
                        //     //     text: __("详情"),
                        //     //     classname: "btn btn-xs btn-info btn-dialog",
                        //     //     icon: "fa fa-eye",
                        //     //     url: "finance/money_logs/edit"
                        //     // },
                        //     // {
                        //     //     name: 'del',
                        //     //     text: '删除',
                        //     //     icon: 'fa fa-trash',
                        //     //     classname: 'btn btn-xs btn-danger btn-delone',
                        //     //     url: 'finance/money_logs/del'
                        //     // },
                        //     ],
                        //     formatter: Table.api.formatter.operate
                        // }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        recyclebin: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    'dragsort_url': ''
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: 'finance/money_logs/recyclebin' + location.search,
                pk: 'id',
                sortName: 'id',
                search:false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'shop_name', title: '店铺名称', align: 'left'},
                        {
                            field: 'delete_dt',
                            title: __('Deletetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            width: '130px',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'Restore',
                                    text: __('Restore'),
                                    classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
                                    icon: 'fa fa-rotate-left',
                                    url: 'finance/money_logs/restore',
                                    refresh: true
                                },
                                {
                                    name: 'Destroy',
                                    text: __('Destroy'),
                                    classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
                                    icon: 'fa fa-times',
                                    url: 'finance/money_logs/destroy',
                                    refresh: true
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        refuse: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
